<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>主页</title>
    <style>
        body {
            font-family: Arial, sans-serif;
            background-color: #f4f4f4;
            margin: 0;
            padding: 0;
        }
        .header {
            background-color: #4CAF50;
            color: white;
            padding: 20px;
            text-align: center;
        }
        .container {
            max-width: 1200px;
            margin: 0 auto;
            padding: 20px;
        }
        .card {
            background-color: white;
            border-radius: 5px;
            box-shadow: 0 0 10px rgba(0, 0, 0, 0.1);
            padding: 20px;
            margin-bottom: 20px;
        }
        .user-info {
            display: flex;
            justify-content: space-between;
            align-items: center;
        }
        .btn {
            background-color: #4CAF50;
            color: white;
            padding: 10px 15px;
            border: none;
            border-radius: 4px;
            cursor: pointer;
            text-decoration: none;
            display: inline-block;
        }
        .btn:hover {
            background-color: #45a049;
        }
        .btn-logout {
            background-color: #f44336;
        }
        .btn-logout:hover {
            background-color: #d32f2f;
        }
        .welcome-message {
            font-size: 24px;
            margin-bottom: 20px;
        }
        .content {
            display: grid;
            grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
            gap: 20px;
        }
        .feature-card {
            background-color: white;
            border-radius: 5px;
            box-shadow: 0 0 10px rgba(0, 0, 0, 0.1);
            padding: 20px;
            text-align: center;
        }
        .feature-card h3 {
            color: #4CAF50;
        }
    </style>
</head>
<body>
    <div class="header">
        <h1>综合设计项目示例-登录模块</h1>
    </div>
    
    <div class="container">
        <div class="card">
            <div class="user-info">
                <div>
                    <div class="welcome-message">欢迎, <span id="username">游客</span>!</div>
                    <p>您的角色是: <span id="role">GUEST</span></p>
                </div>
                <div>
                    <button id="userDetailBtn" class="btn" style="display: none;">查看详细信息</button>
                    <button id="logoutBtn" class="btn btn-logout" style="display: none;">退出登录</button>
                    <a href="/login.html" id="loginLink" class="btn">登录</a>
                </div>
            </div>
        </div>
        
        <div class="content">
            <div class="feature-card">
                <h3>用户认证</h3>
                <p>基于JWT的用户认证系统，支持多种用户角色。</p>
            </div>
            <div class="feature-card">
                <h3>RESTful API</h3>
                <p>提供标准的RESTful API接口，便于前后端分离开发。</p>
            </div>
            <div class="feature-card">
                <h3>Spring Boot</h3>
                <p>使用Spring Boot框架，快速构建独立的、生产级别的Spring应用程序。</p>
            </div>
        </div>
    </div>

    <script>
        // 页面加载时检查用户登录状态
        window.onload = function() {
            const token = localStorage.getItem('token');
            const username = localStorage.getItem('username');
            const role = localStorage.getItem('role');
            
            if (token && username) {
                // 用户已登录
                document.getElementById('username').textContent = username;
                document.getElementById('role').textContent = role;
                document.getElementById('userDetailBtn').style.display = 'inline-block';
                document.getElementById('logoutBtn').style.display = 'inline-block';
                document.getElementById('loginLink').style.display = 'none';
            } else {
                // 用户未登录
                document.getElementById('username').textContent = '游客';
                document.getElementById('role').textContent = 'GUEST';
                document.getElementById('userDetailBtn').style.display = 'none';
                document.getElementById('logoutBtn').style.display = 'none';
                document.getElementById('loginLink').style.display = 'inline-block';
            }
        };
        
        // 查看用户详细信息
        document.getElementById('userDetailBtn').addEventListener('click', function() {
            window.location.href = '/user-info.html';
        });
        
        // 退出登录
        document.getElementById('logoutBtn').addEventListener('click', function() {
            localStorage.removeItem('token');
            localStorage.removeItem('username');
            localStorage.removeItem('role');
            // 直接跳转到登录页面，而不是刷新当前页面
            window.location.href = '/login.html';
        });
    </script>
</body>
</html>